﻿using System.Linq;
using MRGSP.SurveyMaster.Core.Model;

namespace MRGSP.SurveyMaster.Service.Utils
{
    public static class Extensions
    {
        public static bool HasChildren(this Question question)
        {
            return question.Children.Count() > 0;
        }

        public static bool HasParent(this Question question)
        {
            return question.ParentId.HasValue;
        }

        public static string BuildLabel(this Question question)
        {
            return string.Format("<label for='q{0}'>{1}</label>", question.Id, question.Text);
        }

        public static string Colorize(this string text, Question question)
        {
            text = text.Mandatory(question);
            if (question.Red) return string.Format("<span class=\"redy\">{0}</span>", text);
            if (question.Green) return string.Format("<span class=\"greeny\">{0}</span>", text);
            return text;
        }

        public static string Mandatory(this string text, Question question)
        {
            return question.Mandatory ? string.Format("{0} *", text) : text;
        }
    }
}